<?php
/**
 * Login
 * @Description: 登录控制器逻辑
 * @Author: chenbool <30024167@qq.com>
 * @Github: https://github.com/chenbool
 */
namespace app\index\controller;
use think\Controller;

class Login extends Controller
{
    /**
     * 登录页面渲染
     * @route  /login/index
     * @method get
     * @access public
     * @return view
     */
    public function index()
    {
        return view();
    }

    /**
     * 登录页面渲染
     * @route  /login/login
     * @method post
     * @access public
     * @param  array $param
     * @table  user
     * @return json
     */
    public function login()
    {
        request()->isPost() || _Json('非法请求',-10);
        $param = input();
        // 验证
        // validate('User');
        // 查询用户
        $user = model('User')->getByUsername($param['username']);
        $user || _Json('账号不存在',-10);
        // 判断用户是否存在
        ( $user['password'] != md5($param['password']) ) && _Json('密码错误',-10);
        session('user_info',$user);
        return [
            'error' =>  0,
            'msg'   =>  '登录成功'
        ];
    }

}
